#!/usr/bin/env python

## Extracts the clausal/phrasal parts of the if-then sentence.

# Usage:  ~                (meant to be used modularly)

import string, sys, re

def getEI(sentence):
	"""Gets the clausal/phrasal parts of a sentence."""
	ifs = "(if|while|when|given)"
	thens = "(then|therefore|ergo)"
	pattern = ifs + " (.*) " + thens + " (.*)"
	splitup = re.match(pattern, sentence, re.I)
	# print splitup.groups(0)
	return (strip_punc(splitup.group(2)), strip_punc(splitup.group(4)))

def strip_punc(str):
	"""Strips the unncessary punctuation from the rear end of the clauses."""
	## We'll leave this is for more conventional-looking strings.
	if (str.strip()[-1] in [".", ",", ";"]):	str = str.strip()[-1]
	## This takes our type-0 tokenization into account.
	if (str.split()[-1] in ["&comma", "&period", ";", "&colon", "&amp"]):
		str = " ".join(str.split()[:-1])
	return str

if (__name__ == "__main__"):
	string = raw_input("Type a sentence.  Now.  ")
	(ifc, thenc) = getEI(string)
	print "EVIDENCE: ", ifc
	print "INFERENCE: ", thenc
